using Microsoft.OpenApi.Models;

namespace PaddleOCRSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("Swagger", new OpenApiInfo { Title = "PaddleOCRSharp" });
                options.CustomSchemaIds(x => x.FullName);

                var basePath = System.AppDomain.CurrentDomain.BaseDirectory;

                var files = Directory.GetFiles(basePath, "PaddleOCRSharp.xml");
                foreach (var file in files)
                    options.IncludeXmlComments(file, true);

            });

            var app = builder.Build();

            app.UseCors(x => x
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader());

            // Configure the HTTP request pipeline.
            app.UseSwagger(c =>
            {
                c.RouteTemplate = "{documentName}/swagger.json";
                c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Servers = new List<OpenApiServer> { new OpenApiServer { Url = String.Empty } });
            });

            app.UseSwaggerUI(c => { c.SwaggerEndpoint("../Swagger/swagger.json", "PaddleOCRSharpApi"); });

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}